package br.com.app.activity;

import br.com.app.R;
import greendroid.app.GDActivity;
import greendroid.widget.ActionBarItem;
import greendroid.widget.ActionBarItem.Type;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class PrincipalActivity extends GDActivity {
	/** Called when the activity is first created. */
	private final int EXIT = 0;
	private ImageView btProduto, btPedido;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setActionBarContentView(R.layout.main);
		initActionBar();

		btProduto = (ImageView) findViewById(R.principal.btProduto);
		btProduto.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(PrincipalActivity.this,ListaProdutosActivity.class));
			}
		});

		btProduto.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				LinearLayout linLay = (LinearLayout) findViewById(R.principal.lproduto);
				if (event.getAction() == 1) {
					linLay.setBackgroundColor(Color.parseColor("#C0D8F0"));
				} else {
					linLay.setBackgroundColor(Color.parseColor("#E3E3E3"));
				}

				return false;
			}
		});

		btPedido = (ImageView) findViewById(R.principal.btPedido);
		btPedido.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(PrincipalActivity.this,ListaPedidosActivity.class));
			}
		});

		btPedido.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				LinearLayout linLay2 = (LinearLayout) findViewById(R.principal.lpedido);
				if (event.getAction() == 1) {
					linLay2.setBackgroundColor(Color.parseColor("#C0D8F0"));
				} else {
					linLay2.setBackgroundColor(Color.parseColor("#E3E3E3"));
				}

				return false;
			}
		});
	}
	
	@Override
	public void onAttachedToWindow() {
	    super.onAttachedToWindow();
	    Window window = getWindow();
	    window.setFormat(PixelFormat.RGBA_8888);
	}

	private void initActionBar() {
		addActionBarItem(Type.TakePhoto, EXIT).setDrawable(R.drawable.exit);
		//getActionBar().setBackgroundColor(Color.parseColor("#336699"));
		getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.bgactionbar));
		getActionBar().removeViewAt(0);
		getActionBar().setTitle("Controle de Compras");
	}

	@Override
	public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
		switch (item.getItemId()) {
		case EXIT:
			// Toast.makeText(getApplicationContext(),
			// item.getItemId(), Toast.LENGTH_SHORT).show();
			finish();
			break;
		default:
			return super.onHandleActionBarItemClick(item, position);
		}

		return true;
	}

}